package com.movie.comm.utils;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class TextFileUtil {
		/**
		* @Title: read 
		* @Description: TODO(描述这个方法的作用) 
		* @param 读取指定路径文件
		* @return  String    返回字符串
		* @throws 
		*/
		public static String read(String filePath) {
			StringBuilder str = new StringBuilder();
			BufferedReader in = null;
			try {
				in = new BufferedReader(new FileReader(filePath));
				String s;
				try {
					while ((s = in.readLine()) != null)
						str.append(s + '\n');
				} finally {
					in.close();
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return str.toString();
		}
	 

		
		/**
		* @Title: write 写入指定的文本文件
		* @Description: TODO(描述这个方法的作用) 
		* @param  filePath  要写入的文件所在的目录
		* @param  append  boolean类型  append为true表示追加，false表示重头开始写
		* @param  text    要写入的内容
		* @return void    空返回类型
		* @throws 
		 */
		public static void write(String filePath, boolean append, String text) {
			if (text == null)
				return;
			try {
				BufferedWriter out = new BufferedWriter(new FileWriter(filePath,
						append));
				try {
					out.write(text);
				} finally {
					out.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	
}
